package com.intramirror.product.filter;

import com.intramirror.product.entity.AggregateRule;
import com.intramirror.product.entity.SpuBoutiqueImgSort;
import com.intramirror.product.service.IAggregateService;
import com.intramirror.product.utils.AggregateRuleManagement;
import java.util.List;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created on 2018/1/30.
 * @author 123
 */
@WebListener
public class ProductServletListener implements ServletContextListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProductServletListener.class);

    @Autowired
    IAggregateService aggregateService;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        LOGGER.info("Product Servlet initialized.");
        List<AggregateRule> listRule = aggregateService.listAllAggregateRule();
        LOGGER.info("Already get {} rule for aggregate product.", listRule.size());
        AggregateRuleManagement.getInstance().setRuleList(listRule);

        List<SpuBoutiqueImgSort> listSpuBoutiqueImgSort = aggregateService.listAllBoutiqueImgSort();
        LOGGER.info("Already get {} boutique img sort for aggregate product.", listSpuBoutiqueImgSort.size());
        AggregateRuleManagement.getInstance().setBoutiqueImgSort(listSpuBoutiqueImgSort);

    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
